<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2017/10/23
  Time: 12:58
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<title>资源列表</title>
<body>
<style>

    .table-bordered > tbody > tr > td, .table-bordered > tbody > tr > th, .table-bordered > tfoot > tr > td, .table-bordered > tfoot > tr > th, .table-bordered > thead > tr > td, .table-bordered > thead > tr > th {
        border: 1px solid #e7e7e7
    }
    .row{
        margin-top: 10px;
    }

</style>

<div class="container-fluid">
    <div class="row">
        <div class="col-lg-4">
            <button type="button" class="btn btn-primary btn-sm waves-effect waves-light" onclick="add()">添加</button>
        </div>
    </div>
    <div class="row">
        <div class="col-lg-12">
            <table class="table table-hover table-condensed table-bordered " id="treetable">
                <thead class="bg-default">
                <tr>
                    <th style="text-align:center ">
                        资源名称
                    </th>
                    <th style="width:100px;text-align:center">
                        所属应用
                    </th>
                    <th style="width:150px;text-align:center">
                        资源代码
                    </th>
                    <th  style="width:100px;text-align:center">
                        资源类型
                    </th>
                    <th style="width:100px;text-align:center">
                        资源URL
                    </th>
                    <th style="width:100px;text-align:center">
                        操作
                    </th>
                </tr>
                </thead>
                <tbody>

                <c:forEach items="${resourceList}" var="resource">
                    <c:choose>
                        <c:when test="${resource.resourcePid eq 0}">
                            <tr data-id="${resource.id}" data-pid="">
                                <td> ${resource.resourceName}</td>
                                <td class="text-center">
                                    所属应用
                                </td>
                                <td class="text-center">${resource.resourceCode}</td>
                                <c:if test="${resource.resourceType eq 0}">
                                    <td class="text-center">内部URL</td>
                                </c:if>
                                <c:if test="${resource.resourceType eq 1}">
                                    <td class="text-center">内部按钮</td>
                                </c:if>
                                <c:if test="${resource.resourceType eq 2}">
                                    <td class="text-center">外部链接</td>
                                </c:if>
                                <td class="text-center">${resource.resourceUrl}</td>
                                <td class="text-center">
                                    <button type="button" class="btn btn-warning btn-sm waves-effect waves-light">编辑</button>
                                    &nbsp;
                                    <button type="button" class="btn btn-danger btn-sm waves-effect waves-light dodel">删除</button>
                                </td>
                            </tr>
                        </c:when>
                        <c:otherwise>
                            <tr data-id="${resource.id}" data-pid="${resource.resourcePid}">
                                <td> ${resource.resourceName}</td>
                                <td class="text-center">
                                    所属应用
                                </td>
                                <td class="text-center">${resource.resourceCode}</td>
                                <c:if test="${resource.resourceType eq 0}">
                                    <td class="text-center">内部URL</td>
                                </c:if>
                                <c:if test="${resource.resourceType eq 1}">
                                    <td class="text-center">内部按钮</td>
                                </c:if>
                                <c:if test="${resource.resourceType eq 2}">
                                    <td class="text-center">外部链接</td>
                                </c:if>
                                <td class="text-center">${resource.resourceUrl}</td>
                                <td class="text-center">
                                    <button type="button" class="btn btn-warning btn-sm waves-effect waves-light">编辑</button>
                                    &nbsp;
                                    <button type="button" id="del" class="btn btn-danger btn-sm waves-effect waves-light dodel">删除</button>
                                </td>
                            </tr>
                        </c:otherwise>
                    </c:choose>
                </c:forEach>
                </tbody>
            </table>
        </div>
    </div>

</div>



<script type="text/javascript">
    /**
     * Created by harris on 2017/1/17.
     */
    $(function () {
        "use strict";

        var treetable = $('#treetable').BootstrapTreeTable({
//        levelSpacing: 20,//级次间距 px
//        column: 0,//指定排序列号
            expandlevel: 1,//默认展开级次
            expandAll: false,//是否全部展开
            collapseAll: false,//是否全部关闭
//        expendedIcon: '<span class="glyphicon glyphicon-menu-down"></span>',//非叶子节点展开图标
//        collapsedIcon: '<span class="glyphicon glyphicon-menu-right"></span>',//非叶子节点关闭图标
            maxResult: ''//搜索最大结果集，超过将停止返回结果
        }).on("initialized.bs.treetable", function () {
            var count = treetable.BootstrapTreeTable('getMaxLevel');
            createExpandButton(count);
            doDelete()
        });

        function createExpandButton(count) {
            for (var i = 1; i <= count; i++) {
                var $btn = $('<li><a href="#" class="expendlevel" data-level="' + i + '">' + i + '</a></li>');
                $('.pagination').append($btn);
            }
            $('.expendlevel').click(function (e) {
                e.preventDefault();
                var level = $(this).data('level');
                $('#treetable').BootstrapTreeTable('expendLevel', level);
            })
        }
        //删除资源数据
        function doDelete(){
            $('.dodel').on('click', function (e) {
                e.preventDefault();
                var node = $(this).parents('tr');
                $('#treetable').BootstrapTreeTable('removeByNode', node,function (removeId,callback) {
                    //执行删除节点操作
                    Page.postAjax("${ctx}/resource/delete",{id:removeId},function (data) {
                        if(data.result){
                            //删除成功后回调删除页面节点
                            callback();
                        }
                    })
                });
            })
        }

    });
    //添加资源数据
    function add() {
        Dialog.openUrl("资源添加","${ctx}/resource/add",{
            area: ['70%', '70%'],
            end:function () {
            }
        });
    }
</script>
</body>

